﻿using ChurchDiary.Common;
using ChurchDiary.DAL.Contract;
using ChurchDiary.DAL.Methods;
using ChurchDiary.TableEntity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChurchDiary.BLL
{
    public class BLL_Member
    {
        #region Application
        public string InsertChurchMemberApplication(EntityChurchMemberApplications Applications)
        {
            IMembers m = new DAL_ChurchMember();
            return m.InsertChurchMemberApplication(Applications);
        }
        public string UpdateChurchMemberApplication(EntityChurchMemberApplications Applications)
        {
            IMembers m = new DAL_ChurchMember();
            return m.UpdateChurchMemberApplication(Applications);
        }
        public string DeleteChurchMemberApplication(Guid ApplicationId)
        {
            IMembers m = new DAL_ChurchMember();
            return m.DeleteChurchMemberApplication(ApplicationId);
        }
        public List<EntityChurchMemberApplications> GetChurchMemberApplication(int PageNo, string SearchKey, string Sort, string SortMode,int PerPage)
        {
            IMembers m = new DAL_ChurchMember();
            return m.GetChurchMemberApplication(PageNo, SearchKey, Sort, SortMode, PerPage);
        }
        public EntityChurchMemberApplications GetChurchMemberApplication(Guid ApplicationId)
        {
            IMembers m = new DAL_ChurchMember();
            return m.GetChurchMemberApplication(ApplicationId);
        }
        #endregion Application
        #region ChurchMember Family
        public List<EntityChurchMemberFamily> GetChurchMemberFamilies(int PageNo, string SearchKey, string Sort, string SortMode, int PerPage)
        {
            IMembers m = new DAL_ChurchMember();
            return m.GetChurchMemberFamilies(PageNo, SearchKey, Sort, SortMode, PerPage);
        }
        public string DeleteChurchWorkerFamily(Guid FamilyId)
        {
            IMembers m = new DAL_ChurchMember();
            return m.DeleteChurchWorkerFamily(FamilyId);
        }
        public EntityChurchMemberFamily GetChurchMemberFamily(Guid FamilyId)
        {
            IMembers m = new DAL_ChurchMember();
            return m.GetChurchMemberFamily(FamilyId);
        }
        #endregion ChurchMember Family
        #region ChurchMember
        
        public string TransOldFamilytoChurchMembers()
        {
            IMembers m = new DAL_ChurchMember();
            return m.TransOldFamilytoChurchMembers();
        }
        public string TransOldFamilytoApplicantTable()
        {
            IMembers m = new DAL_ChurchMember();
            return m.TransOldFamilytoApplicantTable();
        }
        public List<EntityChurchMembers> GetChurchMembers(Guid FamilyId)
        {
            IMembers m = new DAL_ChurchMember();
            return m.GetChurchMembers(FamilyId);
        }
        public string InsertChurchMembers(EntityChurchMembers Member)
        {
            IMembers m = new DAL_ChurchMember();
            return m.InsertChurchMembers(Member);
        }
        public string UpdateChurchMembers(EntityChurchMembers Member)
        {
            IMembers m = new DAL_ChurchMember();
            return m.UpdateChurchMembers(Member);
        }
        public string DeleteChurchMembers(Guid MemberId)
        {
            IMembers m = new DAL_ChurchMember();
            return m.DeleteChurchMembers(MemberId);
        }
        public EntityChurchMembers GetChurchMember(Guid FamilyId)
        {
            IMembers m = new DAL_ChurchMember();
            return m.GetChurchMember(FamilyId);
        }
        public List<EntityChurchMembers> GetChurchMembers(int PageNo, string SearchKey, string Sort, string SortMode, int PerPage)
        {
            IMembers m = new DAL_ChurchMember();
            return m.GetChurchMembers(PageNo, SearchKey, Sort, SortMode, PerPage);
        }
        public List<EntityChurchMembers> GetAllChurchMemberByChurch()
        {
            IMembers m = new DAL_ChurchMember();
            return m.GetChurchMembers();
        }
        public List<EntityChurchMembers> GetBirthDayList()
        {
            IMembers m = new DAL_ChurchMember();
            return m.GetBirthDayList(Current.ChurchId);
        }
        #endregion
        #region ChurchMember Jobtitle
        public string InsertChurchMemberJobtitle(EntityChurchMemberJobtitle Jobtitle)
        {
            IMembers Mem = new DAL_ChurchMember();
            return Mem.InsertChurchMemberJobtitle(Jobtitle);
        }
        public string UpdateChurchMemberJobtitle(EntityChurchMemberJobtitle Jobtitle)
        {
            IMembers Mem = new DAL_ChurchMember();
            return Mem.UpdateChurchMemberJobtitle(Jobtitle);
        }
        public string DeleteChurchMemberJobtitle(Guid JobtitleId)
        {
            IMembers Mem = new DAL_ChurchMember();
            return Mem.DeleteChurchMemberJobtitle(JobtitleId);
        }
        public EntityChurchMemberJobtitle GetChurchMemberJobtitle(Guid JobtitleId)
        {
            IMembers Mem = new DAL_ChurchMember();
            return Mem.GetChurchMemberJobtitle(JobtitleId);
        }
        public List<EntityChurchMemberJobtitle> GetChurchMemberJobtitle()
        {
            IMembers Mem = new DAL_ChurchMember();
            return Mem.GetChurchMemberJobtitle();
        }
        public List<EntityChurchMemberJobtitle> GetChurchMemberJobtitle(int PageNo, string SearchKey, string Sort, string SortMode, int PerPage)
        {
            IMembers Mem = new DAL_ChurchMember();
            return Mem.GetChurchMemberJobtitle(PageNo, SearchKey, Sort, SortMode, PerPage);
        }
        #endregion region ChurchMember Jobtitle
        /*#region Family

        public string UpdateMember(EntityMembers Members)
        {
            IMembers m = new DAL_Members();
            return m.UpdateMember(Members);
        }
        public List<EntityMembers> GetFamiliesWithMembers()
        {
            IMembers m = new DAL_Members();
            return m.GetFamiliesWithMembers(Current.ChurchId);
        }
        public List<EntityMembers> GetFamiliesWithMembersSearch(string SearchKey)
        {
            IMembers m = new DAL_Members();
            return m.GetFamiliesWithMembersSearch(SearchKey);
        }
        public DataTable GetAllFamilyInChurchReport()
        {
            IMembers m = new DAL_Members();
            return m.GetAllFamilyInChurchReport();
        }
        public List<EntityMembers> GetMembers(int PageNo, string SearchKey, string Sort, string SortMode)
        {
            IMembers m = new DAL_Members();
            return m.GetMembers(PageNo, SearchKey, Sort, SortMode);
        }
        public EntityMembers GetMember(Guid FamilyId)
        {
            IMembers m = new DAL_Members();
            return m.GetMember(FamilyId);
        }
        public string DeleteMember(Guid FamilyId)
        {
            IMembers m = new DAL_Members();
            return m.DeleteMember(FamilyId);
        }
        public string GetMemberList(List<EntityMembers> Members)
        {
            StringBuilder sbMembers = new StringBuilder();
            int i = 1;
            foreach (EntityMembers lst in Members)
            {

                i += 1;
            }
            return sbMembers.ToString();
        }
        public DataTable GetFamilyDetailsReport(Guid FamilyId)
        {
            IMembers m = new DAL_Members();
            return m.GetFamilyDetailsReport(FamilyId);
        }
        #endregion
        #region Family Members
        
        public string InsertFamilyMembers(EntityFamilyMembers FamilyMembers)
        {
            IMembers m = new DAL_Members();
            return m.InsertFamilyMembers(FamilyMembers);
        }
        public string UpdateFamilyMembers(EntityFamilyMembers FamilyMembers)
        {
            IMembers m = new DAL_Members();
            return m.UpdateFamilyMembers(FamilyMembers);
        }
        public EntityFamilyMembers GetFamilyMember(Guid MemberId)
        {
            IMembers m = new DAL_Members();
            return m.GetFamilyMember(MemberId);
        }
        public EntityMemberFullDetails GetFamilyMemberFulldetails(Guid MemberId)
        {
            IMembers m = new DAL_Members();
            return m.GetFamilyMemberFulldetails(MemberId);
        }
        public List<EntityFamilyMembers> GetFamilyMembers(Guid Familyid)
        {
            IMembers m = new DAL_Members();
            return m.GetFamilyMembers(Familyid);
        }
        public string DeleteFamilyMembers(Guid MemberId)
        {
            IMembers m = new DAL_Members();
            return m.DeleteFamilyMembers(MemberId);
        }
        public string GetFamilyMemberList(List<EntityFamilyMembers> FamilyMembers)
        {
            StringBuilder sbMembers = new StringBuilder();
            int i = 1;
            foreach (EntityFamilyMembers lst in FamilyMembers)
            {
                sbMembers.Append("<tr class=\"even pointer\">");
                //sbMembers.Append("<td class=\" \">" + lst.Name + "</td>");
                sbMembers.Append("<td class=\" \">" + lst.RelationShip.RelationShipName + "</td>");
                sbMembers.Append("<td class=\" \">" + lst.Email + "</td>");
                sbMembers.Append("<td class=\" \">" + lst.Phone + "</td>");
                sbMembers.Append("<td class=\" \">" + lst.DateOfBirth + "</td>");
                sbMembers.Append("<td class=\" \">" + lst.DateOfSalvation + "</td>");
                sbMembers.Append("<td class=\" \">");
                sbMembers.Append("<ul class=\"actionicons\">");
                sbMembers.Append("<li><a data-id=" + lst.MemberId + " data-toggle=\"tooltip\" class=\"del confirmbox\" data-placement=\"bottom\" title=\"\" data-original-title=\"Delete\"><i class=\"fa fa-trash\"></i></a></li>");
                sbMembers.Append("<li><a data-id=" + lst.MemberId + " data-toggle=\"tooltip\" class=\"edit\" data-placement=\"bottom\" title=\"\" data-original-title=\"Edit\"><i class=\"fa fa-pencil\"></i></a></li>");
                sbMembers.Append("<li><a href=\"../../Church/AddMembers/MemberInfo?MemberId=" + lst.MemberId + "\" class=\"view\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"\" data-original-title=\"info\"><i class=\"fa fa-info-circle\"></i></a></li>");
                sbMembers.Append("</ul>");
                sbMembers.Append("</td>");
                sbMembers.Append("</tr>");
                i += 1;
            }
            return sbMembers.ToString();
        }
        public List<EntitySelectFamilyDetails> GetFamilyMembersByChurchId(Guid ChurchId)
        {
            IMembers Bap = new DAL_Members();
            return Bap.GetFamilyMembersByChurchId(ChurchId);
        }
        public string GetFamilyAndMembersDropdown(List<EntitySelectFamilyDetails> SelectFamilyDetails)
        {
            var FamilyId = new Guid();
            int i = 0;
            StringBuilder sbMembers = new StringBuilder();
            foreach (EntitySelectFamilyDetails lst in SelectFamilyDetails)
            {

                if (FamilyId != lst.FamilyId)
                {
                    if (i == 0)
                    {
                        sbMembers.Append("<option value='0'>Please Select</option>");
                    }
                    if (i > 0)
                    {
                        sbMembers.Append("</optgroup>");
                    }
                    sbMembers.Append("<optgroup label='" + lst.FamilyName + "'>");
                    FamilyId=lst.FamilyId;
                    i += 1;
                }
                sbMembers.Append("<option value=" + lst.MemberId + ">" + lst.MemberName + "</option>");
            }
            return sbMembers.ToString();
        }
        public List<EntityFamilyMembers> GetFamilyMembersByChurch(Guid Churchid, string SearchText)
        {
            IMembers Bap = new DAL_Members();
            return Bap.GetFamilyMembersByChurch(Churchid, SearchText);
        }
        public DataTable GetFamilyMembersReport()
        {
            IMembers Bap = new DAL_Members();
            return Bap.GetFamilyMembersReport(Current.ChurchId);
        }
        #endregion
        #region Baptism
        public string AddBaptism(EntityBaptism Baptism)
        {
            IMembers Bap = new DAL_Members();
            return Bap.InsertBaptism(Baptism);
        }
        public string UpdateBaptism(EntityBaptism Baptism)
        {
            IMembers Bap = new DAL_Members();
            return Bap.UpdateBaptism(Baptism);
        }
        public string DeleteBaptism(Guid BaptismId)
        {
            IMembers Bap = new DAL_Members();
            return Bap.DeleteBaptism(BaptismId);
        }
        public List<EntityBaptism> GetBaptism()
        {
            IMembers Bap = new DAL_Members();
            return Bap.GetBaptism();
        }
        public EntityBaptism GetBaptism(Guid BaptismId)
        {
            IMembers Bap = new DAL_Members();
            return Bap.GetBaptism(BaptismId);
        }
        public string GetBaptismList(List<EntityBaptism> Baptism)
        {
            StringBuilder sbBaptism = new StringBuilder();
            foreach (EntityBaptism lst in Baptism)
            {
                sbBaptism.Append("<tr class=\"even pointer\">");
                sbBaptism.Append("<td class=\" \">" + lst.FamilyNo + "</td>");
                sbBaptism.Append("<td class=\" \">" + lst.Name + "</td>");
                sbBaptism.Append("<td class=\" \">" + lst.Gender + "</td>");
                sbBaptism.Append("<td class=\" \">" + lst.FamilyName + "</td>");
                sbBaptism.Append("<td class=\" \">" + CommonFunction.ConvertDate(lst.DateOfBaptism) + "</td>");
                sbBaptism.Append("<td class=\" \">" + lst.PlaceOfBaptism + "</td>");
                sbBaptism.Append("<td class=\" \">" + lst.NameOfBaptizer + "</td>");
                sbBaptism.Append("<td class=\" \">");
                sbBaptism.Append("<ul class=\"actionicons\">");
                sbBaptism.Append("<li><a data-id=" + lst.BaptismId + " data-toggle=\"tooltip\" class=\"del confirmbox\" data-placement=\"bottom\" title=\"\" data-original-title=\"Delete\"><i class=\"fa fa-trash\"></i></a></li>");
                sbBaptism.Append("<li><a data-id=" + lst.BaptismId + " data-toggle=\"tooltip\" class=\"edit\" data-placement=\"bottom\" title=\"\" data-original-title=\"Edit\"><i class=\"fa fa-pencil\"></i></a></li>");
                sbBaptism.Append("<li><a href='BaptismRegister/PrintBaptism?BaptismId=" + lst.BaptismId + "' target=\"_blank\" data-id=" + lst.BaptismId + " class=\"view\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"\" data-original-title=\"info\"><i class=\"fa fa-print\"></i></a></li>");
                sbBaptism.Append("</ul>");
                sbBaptism.Append("</td>");
                sbBaptism.Append("</tr>");
            }
            return sbBaptism.ToString();
        }
        public DataTable GetBaptismDetailsforPrint(Guid BaptismId)
        {
            IMembers Bap = new DAL_Members();
            return Bap.GetBaptismDetailsforPrint(BaptismId);
        }
        #endregion
        #region Membershipfee
        public string AddMembershipfee(EntityMembershipfee Membershipfee)
        {
            IMembers Bap = new DAL_Members();
            return Bap.InsertMembershipfee(Membershipfee);
        }
        public string UpdateMembershipfee(EntityMembershipfee Membershipfee)
        {
            IMembers Bap = new DAL_Members();
            return Bap.UpdateBaptismMembershipfee(Membershipfee);
        }
        public string DeleteMembershipfee(Guid FeeId)
        {
            IMembers Bap = new DAL_Members();
            return Bap.DeleteMembershipfee(FeeId);
        }
        public List<EntityMembershipfee> GetMembershipfee(string Year,Guid ChurchId)
        {
            IMembers Bap = new DAL_Members();
            return Bap.GetMembershipfee(Year, ChurchId);
        }
        public EntityMembershipfee GetMembershipfee(Guid FeeId)
        {
            IMembers Bap = new DAL_Members();
            return Bap.GetMembershipfee(FeeId);
        }
        public string GetMembershipfeeList(List<EntityMembershipfee> Membershipfee)
        {
            StringBuilder sbMembers = new StringBuilder();
            int i = 1;
            foreach (EntityMembershipfee lst in Membershipfee)
            {
                //sbMembers.Append("<tr class=\"even pointer\">");
                //sbMembers.Append("<td class=\" \">" + lst.Members.FamilyHeadName + "</td>");
                //sbMembers.Append("<td class=\" \">" + lst.Members.familyNo + "</td>");
                //sbMembers.Append("<td class=\" \">" + lst.FamilyMembers.Name + "</td>");
                //sbMembers.Append("<td class=\" \">" + CommonFunction.ConvertDate(lst.DateofPayment) + "</td>");
                //sbMembers.Append("<td class=\" \">" + lst.Amount + "</td>");
                //sbMembers.Append("<td class=\" \">");
                //sbMembers.Append("<ul class=\"actionicons\">");
                //sbMembers.Append("<li><a data-year=" + lst.Year + " data-id=" + lst.FeeId + " data-toggle=\"tooltip\" class=\"del confirmbox\" data-placement=\"bottom\" title=\"\" data-original-title=\"Delete\"><i class=\"fa fa-trash\"></i></a></li>");
                //sbMembers.Append("<li><a data-id=" + lst.FeeId + " data-toggle=\"tooltip\" class=\"edit\" data-placement=\"bottom\" title=\"\" data-original-title=\"Edit\"><i class=\"fa fa-pencil\"></i></a></li>");
                //sbMembers.Append("<li><a href=\"../../Church/AddMembers/info?FamilyId=" + lst.FamilyId + "\" class=\"view\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"\" data-original-title=\"info\"><i class=\"fa fa-print\"></i></a></li>");
                //sbMembers.Append("</ul>");
                //sbMembers.Append("</td>");
                //sbMembers.Append("</tr>");
                i += 1;
            }
            return sbMembers.ToString();
        }
        #endregion
        #region AssignJobtitle
        public string InsertMemberRoles(EntityMemberRoles MemberRoles)
        {
            IMembers Bap = new DAL_Members();
            return Bap.InsertMemberRoles(MemberRoles);
        }
        public string UpdateMemberRoles(EntityMemberRoles MemberRoles)
        {
            IMembers Bap = new DAL_Members();
            return Bap.UpdateMemberRoles(MemberRoles);
        }
        public string DeleteMemberRoles(Guid RoleId)
        {
            IMembers Bap = new DAL_Members();
            return Bap.DeleteMemberRoles(RoleId);
        }
        public List<EntityMemberRoles> GetMemberRoles()
        {
            IMembers Bap = new DAL_Members();
            return Bap.GetMemberRoles(Current.ChurchId);
        }
        #endregion
        #region Child Dedication
        public string InsertChildDedication(EntityChildDedications ChildDedication)
        {
            IMembers m = new DAL_Members();
            return m.InsertChildDedication(ChildDedication);
        }
        public string UpdateChildDedication(EntityChildDedications ChildDedication)
        {
            IMembers m = new DAL_Members();
            return m.UpdateChildDedication(ChildDedication);
        }
        public List<EntityChildDedications> GetChildDedications()
        {
            IMembers m = new DAL_Members();
            return m.GetChildDedications();
        }
        public EntityChildDedications GetChildDedication(Guid ChildDedicationId)
        {
            IMembers m = new DAL_Members();
            return m.GetChildDedication(ChildDedicationId);
        }
        public string DeleteChildDedication(Guid ChildDedicationId)
        {
            IMembers m = new DAL_Members();
            return m.DeleteChildDedication(ChildDedicationId);
        }
        #endregion*/
    }
}
